import { LotHeadLabelT, MapLayerSelectT, slitHeadBackT } from '@/typings/global';
import { onlyGetChildFlaw, onlyGetChildFlawDoff } from '@/utils/tool';

// 处理卷的头部数据
export const handleLotHead = (backData: slitHeadBackT, headLabel: Record<string, LotHeadLabelT>) => {
  const finRes = {
    ...headLabel
  } as any;
  Object.keys(finRes).forEach(key => {
    if (key == 'dimensionsSize') {
      // finRes['dimensionsSize'].value = `${backData.dimensions.size}(${backData.dimensions.longSizeLen}*${backData.dimensions.shortSizeLen})`;
      finRes['dimensionsSize'].value = `${backData.size ? backData.size : 0}(${backData.sizeLong?.toFixed(2) || 0}*${backData.sizeShort?.toFixed(2) || 0})`;
    } else {
      const isExit = backData.hasOwnProperty(key);
      if (isExit) {
        if (key == 'layerId') {
          finRes[key].value = backData[key] ? backData[key] : '空';
        } else {
          finRes[key].value = backData[key] ? backData[key] : 0;
        }
      }
    }
  });
  return finRes;
};

/**
 * 处理缺陷--传入其他查询条件，进行合并
 * @param lotStore
 * @param commonStore
 * @param params
 * @returns
 */
export const handleFlawTypeParams = (lotStore, commonStore, params?) => {
  let newParams = {
    ...params,
    flawTypeList: {
      doff: [],
      pol: [],
      piantiehou: []
    }
  } as any;
  //   const doff = lotStore.flawTypeStorage.doff;
  const pol = lotStore.flawTypeStorage.pol;
  const piantiehou = lotStore.flawTypeStorage.piantiehou;

  newParams.flawTypeList.doff = lotStore.checkedFlawTypePmp;
  //   console.log('前制程直接传参缺陷id:', lotStore.checkedFlawTypePmp);
  //   if (doff.length && doff[0] !== 'all') {
  //     newParams.flawTypeList.doff = onlyGetChildFlawDoff(doff, commonStore.doffResult.fatherMap,commonStore.doffResult.stationMap);
  //   } else if (doff.length === 1 && doff[0] === 'all') {
  //     // delete newParams.flawTypeList.doff;
  //     newParams.flawTypeList.doff = [...commonStore.doffResult.flawTypeSymbolMap.keys()];
  //   }

  if (pol.length && pol[0] !== 'all') {
    newParams.flawTypeList.pol = onlyGetChildFlaw(pol, commonStore.polResult.fatherMap);
  } else if (pol.length === 1 && pol[0] === 'all') {
    delete newParams.flawTypeList.pol;
  }

  if (piantiehou.length && piantiehou[0] !== 'all') {
    newParams.flawTypeList.piantiehou = onlyGetChildFlaw(piantiehou, commonStore.pianResult.fatherMap);
  } else if (piantiehou.length === 1 && piantiehou[0] === 'all') {
    delete newParams.flawTypeList.piantiehou;
  }

  if (!Object.keys(newParams.flawTypeList).length) {
    delete newParams.flawTypeList;
  }

  return newParams;
};
